<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>已购课程|私教预约系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <meta name="author" content="yinqi" />
    <link rel="shortcut icon" type="image/x-icon" href="../favicon.ico" />
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/materialdesignicons.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.min.css" />
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css"/>
    <link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="../css/styles.css">
    <style type="text/css">
        p{
            font-family: tahoma,geneva,sans-serif;
            font-size: 24px;
            text-align: center;
        }
        table{
            margin-top: 30px;
        }
    </style>

</head>
<body>

<h3 class="col-sm-offset-5"><span class="label label-default">已购课程</span></h3>

<div id="container">
    <div class="col-xl-10">
        <table class="table table-bordered table-striped table-hover">
            <thead>
            <tr>
                <td>#</td>
                <td>购买日期</td>
                <td>价格</td>
                <td>课程名</td>
                <td>课程类型</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody id="tbody">

            </tbody>
        </table>
    </div>
</div>
</body>
<script src="../jquery/jquery-3.4.1.min.js"></script>
<script src="../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function (){

        let currentUserId = $.cookie("userid");
        jQuery.post("/getCourseSelectedList", {"userId": currentUserId},function(rst){//处理响应的结果

            let body = "";
            for(let i = 0; i < rst.length; i++)
            {
                let json = rst[i];

                body += "<tr>";
                body += "<td>" + (i + 1) + "</td>";
                body += "<td>" + json.paidDate + "</td>";
                body += "<td>" + json.coursePrice + "</td>";
                body += "<td>" + json.courseName + "</td>";
                body += "<td>" + json.courseType + "</td>";
                body += "<td>";
                body += "<a href='#' onclick='goCourseDetail(\""+json.courseId+"\")'>详情</a>&nbsp;&nbsp;";
                body += "<a href='#' onclick='dropOutCourse(\""+json.courseId+"\")'>退课</a>";
                body += "</td>"
                body += "</tr>";

            }
            jQuery("#tbody").html(body);
        },"json");//表示返回数据的格式
    });

    function goCourseDetail(id){
        $.cookie('currentCourseId', id);
        window.location.replace("courseDetails.html");
    }

    function dropOutCourse(id){
        let currentUserId = $.cookie("userid");
        jQuery.post("/dropCourse", {"userId": currentUserId, "courseId": id}, function (rst){
            if (rst == "退课成功"){
                rst = rst + "，钱款已经退还到账户。"
            }
            alert(rst);
            window.location.reload();
        })
    }

</script>
</html>